

 %
 % Related parameters:
omega0  = 1-beta;
omega1  = beta*alpha/(1 - beta*(1-alpha));  
mu      = -.5*(sigma^2)*alpha/(1-alpha);
mulog   = mu - ((sigma^2)/2);



%% ABEL-EBERLY Natural Wastage. 
%  (This is used to help initialize solution algorithm for boundaries.)
muhat= mu + (1-alpha)*s*lambda;
rho0 = r + s*lambda;
rho1 = rho0 - muhat;
bb   = muhat - .5*(sigma^2);
cc   = 2*(sigma^2)*rho0;
gamma1 = (-bb - sqrt(bb^2 + cc)) / (sigma^2);
gamma2 = (-bb + sqrt(bb^2 + cc)) / (sigma^2);
G0 = 1.5;
foptions = optimoptions('fsolve','Display','off');
[G,fval,exitflag] = fsolve('solve_nwfun', G0, foptions,  c,rho0,omega0,gamma1,gamma2);
if exitflag <1
    disp('WARNING: Failed to solve Abel-Eberly boundaries');
    pause;
else
    thetaG = (G.^gamma2  - G)  ./ (G.^gamma2  - G.^gamma1 );
    phiG   = 1 - (thetaG /gamma1) - ((1-thetaG) /gamma2);
    mLstar = (omega0/rho0) / (phiG*(1-omega1)/rho1);
    mMstar = mLstar*G;
end


%% SOLVE FOR BOUNDARIES: mL, mM, mR, mU.
%  Strategy: Guess lower boundary, mL; solve for others; and verify guess 
%  by checking that left- and right-side derivatives of J are equal
%  at implied mM boundary (upper support of natural wastage region).
%
%  1) Set range for lower boundary.
solve_initialize;
%
%  2) Iterate on lower boundary.
solve_boundaries;

   
%% SS DISTRIBUTION OF Marg Prod over Employment.
%  This yields the CDF of m in each region (G_nw, G_fr, G_ne). 
%  G_all concatenates latter to span the entire support of m.
%  It also yields the associated PDFs and J (marginal value)
%  in each regime. Finally, given the boundaries and CDFs,
%  it computes the unemployed share of searchers.
solve_ssdensity;
    


%% SS DISTRIBUTION of Marg. Product over **Employers**
solve_ssdensity_estab;


%% POLICY FUNCTIONS - Quit and hiring rates.
%  These are embedded in solution of distributions. 
%  This file collects them both and places on same grids. 
solve_policy;


    
    
    